package com.qf.springcloud.airsearch.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RefreshScope      // 记住，后面的其他配置中心的动态刷新，也需要他
public class SearchController {

    @Value("${server.port}")
    private String port;

    @Value("${dev}")
    private String dev;

    @GetMapping("/search/xxx")
    public String xxx(){
        return dev;
    }

    @GetMapping("/search/test")
    public String searchTest() throws InterruptedException {
        int i = 1 / 0;
//        Thread.sleep(2000);
        return "Hello Eureka！！！" + port;
    }



    // 添加功能，返回JSON
    @PostMapping("/search/add")
    public Map add(@RequestBody Map map){
        map.put("search","add");
        return map;
    }


    // 删除功能
    @DeleteMapping("/search/del/{id}")
    public String del(@PathVariable String id) throws InterruptedException {
        Thread.sleep(1100);
        return id;
    }

    // 修改操作
    @PostMapping("/search/update")
    public String update(String name, Integer age, Date birthday){
        return name + "," + age + "," + birthday;
    }

}
